<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const goodsList = [
      {
        id: '4001172',
        name: '张三',
        price: 289.9,
        count: 2,
        spec: { color: '白色' }
      },
      {
        id: '4001009',
        name: '李四',
        price: 109.8,
        count: 3,
        spec: { size: '40cm*40cm', color: '黑色' }
      },
      {
        id: '4001874',
        name: '老六',
        price: 488,
        count: 1,
        spec: { color: '青色', sum: '一大四小' }
      },
      {
        id: '4001649',
        name: '老六',
        price: 139,
        count: 1,
        spec: { size: '小号', color: '紫色' },
        gift: '50g茶叶,清洗球,宝马, 奔驰'
      }
    ]

    
    // 封装函数 找到老六这俩项 筛选出来
    // 封装函数 找到老六这个对象 返回整个对象出来
    function getOldsix(name1) {
      const res = goodsList.filter (item=>{
        return item.name == name1
      })
      return res
    }
    console.log(getOldsix('老六'));
    
    
    // 封装函数 把所有的价格累加
    function getsum(goodsList) {
      const res = goodsList.reduce ((prev,item)=>{
        return prev + item.price 
      },0)
      return res
    }
    console.log(getsum(goodsList));
    
    // 数组对象解构出来
    const [a,b,c,d] = goodsList
    console.log(a);
    console.log(b);
    console.log(c);
    console.log(d);



  </script>
</body>
</html>